package com.zhongzhi.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhongzhi.service.TypeService;
import com.zhongzhi.springboot.pojo.Bo;
import com.zhongzhi.springboot.pojo.JsonResult;
import com.zhongzhi.springboot.pojo.Measure;
import com.zhongzhi.springboot.pojo.Type;
/**
 * 机型业务层
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/type/")
public class TypeController {
	@Autowired
	private TypeService typeService;

	//增加机型
	@RequestMapping("insert")
	public JsonResult insert(Type type) {
		Bo bo = typeService.insert(type);
		if(bo.isBool()) {
			//插入数据返回id
			return new JsonResult(200,"增加机型成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"增加机型失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//修改机型
	@RequestMapping("update")
	public JsonResult update(Type type) {
		Bo bo = typeService.update(type);
		if(bo.isBool()) {
			return new JsonResult(200,"修改机型成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"修改机型失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}

	//删除机型(如果机型下面有测试数据,则不能删除)
	@RequestMapping("delete")
	public JsonResult delete(Integer id) {
		Bo bo = typeService.delete(id);
		if(bo.isBool()) {
			return new JsonResult(200,"删除机型成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"删除机型失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}

	//查询全部机型
	@RequestMapping("select")
	public JsonResult select(Integer pages,Integer line) {
		Bo bo = typeService.select(pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询机型成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询机型失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询全部机型总数
	@RequestMapping("selectSize")
	public JsonResult selectSize() {
		Bo bo = typeService.selectSize();
		if(bo.isBool()) {
			return new JsonResult(200,"查询机型数量成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询机型数量失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	
	//根据id查询机型
	@RequestMapping("selectById")
	public JsonResult selectById(Integer id) {
		Bo bo = typeService.selectById(id);
		if(bo.isBool()) {
			return new JsonResult(200,"查询机型成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询机型失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//根据机型名称模糊查询机型
	@RequestMapping("selectByDeviceNum")
	public JsonResult selectByDeviceNum(String typeName, Integer pages,Integer line) {
		Bo bo = typeService.selectByDeviceNum(typeName,pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询机型成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询机型失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	
	//根据机型名称模糊查询机型总数
		@RequestMapping("selectByDeviceNumSize")
		public JsonResult selectByDeviceNumSize(String typeName) {
			Bo bo = typeService.selectByDeviceNum(typeName);
			if(bo.isBool()) {
				return new JsonResult(200,"查询机型数量成功",bo.getSize(),bo.getObject());
			}else {
				return new JsonResult(500,"查询机型数量失败: "+bo.getMessage(),bo.getSize(),null);
			}
		}
}
